package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"grpcClient/proto"
	"log"
	"time"
)

func main() {
	conn, err := grpc.Dial(":8080", grpc.WithInsecure())
	if err != nil {
		log.Fatal("1", err)
	}

	defer conn.Close()
	prodClient := product.NewGetProductServiceClient(conn)
	ctx, cancel := context.WithTimeout(context.Background(), time.Second) //超时1秒执行cancel
	defer cancel()

	proRes, err := prodClient.GetProduct(ctx, &product.ReqProduct{Id: 20})
	if err != nil {
		log.Fatal("2", err)
	} else {
		fmt.Println(proRes.Data)
	}

}
